package cn.gok.oa.mpconfig;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

        //获取当前时间格式化String
        LocalDateTime nowDateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        this.setInsertFieldValByName("createTime", dateTimeFormatter.format(nowDateTime),metaObject);
//        this.setInsertFieldValByName("ccc",Long.class,metaObject);
//        setFieldValByName("createTime", dateTimeFormatter.format(nowDateTime), metaObject);
//        this.strictUpdateFill(metaObject,"updateTime",LocalDateTime.class,LocalDateTime.now());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        this.strictUpdateFill(metaObject,"updateTime",LocalDateTime.class,LocalDateTime.now());
    }
}